<template>
  <d2-container better-scroll>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="期货指令" name="first">
        <el-card shadow="never" class="d2-mb">
          <el-form
            class="filter-container"
            ref="egForm"
            :model="form_first"
            label-width="100px"
          >
            <el-row :gutter="20">
              <el-col :span="4">
                <el-form-item label="指令名称">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_first.command_name"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="指令ID">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_first.command_id"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="指令类型">
                  <el-select
                    v-model="form_first.command_type"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in type_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="所属策略名称">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_first.strategy_name"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="所属策略ID">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_first.strategy_id"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="部门名称">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_first.department_name"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="申请人">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_first.creator"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="状态">
                  <el-select v-model="form_first.status" placeholder="请选择">
                    <el-option
                      v-for="item in first_statusData"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="2" style="margin-top:4px;">
                <el-button type="primary" size="small" @click="selectDataone">
                  <d2-icon name="search" /> 查询
                </el-button>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
        <div class="mb">
          <el-button
            type="default"
            size="mini"
            @click="handleFilter_addqhzl(1)"
          >
            <d2-icon name="plus" />
            新增
          </el-button>
          <el-button type="default" size="mini" @click="handleFilter_editCkgl">
            <d2-icon name="edit" />
            修改
          </el-button>
          <el-button
            type="default"
            size="mini"
            icon="el-icon-delete"
            @click="delete_fn"
          >
            删除
          </el-button>
          <el-button
            type="default"
            size="mini"
            icon="el-icon-delete"
            @click="look_fn"
          >
            查看
          </el-button>
          <el-button
            type="default"
            size="mini"
            @click="handleFilter_addqhzl(2)"
          >
            <i class="fa fa-clipboard" aria-hidden="true"></i>
            复制
          </el-button>
          <el-button
            type="default"
            size="mini"
            @click="submit_first_dialogVisible_fn"
            :loading="loading_first"
          >
            <i class="fa fa-calendar-check-o" aria-hidden="true"></i>
            提交审批
          </el-button>
          <el-button
            type="default"
            size="mini"
            @click="handleFilter_qhzlTjsp_tui"
          >
            <i class="fa fa-calendar-times-o" aria-hidden="true"></i>
            退审
          </el-button>
          <el-button type="default" size="mini" @click="tiaozhuan()">
            <i class="fa fa-calendar-plus-o" aria-hidden="true"></i>
            审批历史
          </el-button>
          <el-button
            type="default"
            size="mini"
            @click="handleCleanCacheAndRefreshCurrent(1)"
          >
            <d2-icon name="refresh" />
            刷新
          </el-button>
          <el-button type="default" size="mini" @click="order_fn_first">
            <i class="fa fa-calendar-times-o" aria-hidden="true"></i>
            下达指令
          </el-button>
          <el-button type="default" size="mini" @click="order_fn_first_null">
            <i class="fa fa-calendar-times-o" aria-hidden="true"></i>
            撤销指令
          </el-button>
        </div>
        <el-card shadow="never" class="d2-mb">
          <div>
            <el-table
              :data="tableData_first"
              style="width: 100%"
              border
              highlight-current-row
              @current-change="handleCurrentChange_first"
              :cell-style="{ 'text-align': 'center' }"
              :header-cell-style="{
                background: '#eef1f6',
                'text-align': 'center',
                color: '#606266'
              }"
            >
              <el-table-column type="index" width="55"> </el-table-column>
              <el-table-column label="状态" prop="status"> </el-table-column>
              <el-table-column label="机构名称" prop="org_name">
              </el-table-column>
              <el-table-column label="部门名称" prop="depart_name">
              </el-table-column>
              <el-table-column label="指令名称" prop="command_name">
              </el-table-column>
              <el-table-column label="指令ID" prop="command_id" sortable>
              </el-table-column>
              <el-table-column label="指令类型" prop="command_type">
              </el-table-column>
              <el-table-column label="所属策略名称" prop="strategy_name">
              </el-table-column>
              <el-table-column label="所属策略ID" prop="strategy_id" sortable>
              </el-table-column>
              <el-table-column label="指令开始时间" prop="start_date" sortable>
              </el-table-column>
              <el-table-column label="指令结束时间" prop="end_date" sortable>
              </el-table-column>
              <el-table-column label="申请人" prop="creator_name">
              </el-table-column>
            </el-table>
            <el-pagination
              @current-change="handlePaginationChange"
              :current-page="form_first.page"
              :page-size="form_first.pageSize"
              layout="total, prev, pager, next"
              :total="form_first.pageTotal"
            >
            </el-pagination>
          </div>
        </el-card>
        <el-dialog
          title="期货指令-查看"
          :visible.sync="dialogVisible_look"
          width="80%"
          :append-to-body="true"
        >
          <div class="mb">
            <el-button
              type="default"
              size="mini"
              @click="dialogVisible_look = false"
            >
              <d2-icon name="plus" />
              关闭
            </el-button>
            <el-button type="default" size="mini" @click="tiaozhuan()">
              <d2-icon name="plus" />
              审批历史
            </el-button>
          </div>
          <el-table
            class="d2-mb"
            :data="look_first_data_t"
            border
            fit
            :cell-style="{ 'text-align': 'center' }"
            :header-cell-style="{ 'text-align': 'center' }"
          >
            <el-table-column type="index" label="序号"> </el-table-column>
            <el-table-column prop="strategy_name" label="策略名称">
            </el-table-column>
            <el-table-column prop="strategy_id" label="策略ID">
            </el-table-column>
            <el-table-column prop="command_type" label="指令类型">
            </el-table-column>
            <el-table-column prop="command_name" label="指令名称">
            </el-table-column>
            <el-table-column prop="command_id" label="指令ID">
            </el-table-column>
            <el-table-column label="指令开始时间" prop="start_date">
            </el-table-column>
            <el-table-column prop="end_date" label="指令结束时间">
            </el-table-column>
            <el-table-column prop="depart_name" label="部门名称">
            </el-table-column>
            <el-table-column prop="real_account" label="柜台账号">
            </el-table-column>
            <el-table-column prop="sub_account" label="子账号">
            </el-table-column>
            <el-table-column prop="trader" label="交易员"> </el-table-column>
          </el-table>
          <el-table
            :data="look_first_data_b"
            border
            fit
            :cell-style="{ 'text-align': 'center' }"
            :header-cell-style="{ 'text-align': 'center' }"
          >
            <el-table-column type="index" label="序号"> </el-table-column>
            <el-table-column prop="productName" label="品名"> </el-table-column>
            <el-table-column prop="instrument" label="合约" width="240px">
            </el-table-column>
            <el-table-column prop="direction" label="方向" sortable>
            </el-table-column>
            <el-table-column prop="offset_flag" label="开/平" sortable>
            </el-table-column>
            <el-table-column prop="volume" label="手数" sortable>
            </el-table-column>
            <el-table-column label="价格区间" width="240px">
              <template slot-scope="scope">
                {{ scope.row.min_price }}-{{ scope.row.max_price }}
              </template>
            </el-table-column>
            <el-table-column prop="commodity_unit" label="单位" sortable>
            </el-table-column>
            <el-table-column prop="currency" label="币种" sortable>
            </el-table-column>
            <el-table-column prop="name.remarks" label="备注" sortable>
            </el-table-column>
          </el-table>
        </el-dialog>
      </el-tab-pane>
      <el-tab-pane label="指令自成交" name="second">
        <el-card shadow="never" class="d2-mb">
          <el-form
            class="filter-container"
            ref="egForm"
            :model="form_second"
            label-width="100px"
          >
            <el-row :gutter="20">
              <el-col :span="4">
                <el-form-item label="匹配名称">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_second.match_name"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="匹配ID">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_second.match_id"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="创建日期">
                  <el-date-picker
                    v-model="form_second.create_date"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                    style="width: 100%;"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label="创建人">
                  <el-input
                    placeholder="请输入内容"
                    v-model="form_second.creator"
                    clearable
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="2" style="margin-top:4px;">
                <el-button type="primary" size="mini" @click="selectSecond">
                  <d2-icon name="search" /> 查询
                </el-button>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
        <div class="mb">
          <el-button type="default" size="mini" @click="handleFilter_addzlzcj">
            <d2-icon name="plus" />
            新增
          </el-button>
          <el-button type="default" size="mini" @click="update_second_fn">
            <d2-icon name="edit" />
            修改
          </el-button>
          <el-button
            type="default"
            size="mini"
            icon="el-icon-delete"
            @click="handleFilter_delCkgl"
          >
            删除
          </el-button>
          <el-button type="default" size="mini" @click="look_second_fn">
            <d2-icon name="refresh" />
            查看
          </el-button>
          <el-button
            type="default"
            size="mini"
            @click="handleCleanCacheAndRefreshCurrent(2)"
          >
            <d2-icon name="refresh" />
            刷新
          </el-button>
        </div>
        <el-card shadow="never" class="d2-mb titleline">
          <div>
            <el-table
              :data="tableData_second"
              style="width: 100%"
              highlight-current-row
              border
              :cell-style="{ 'text-align': 'center' }"
              :header-cell-style="{
                background: '#eef1f6',
                'text-align': 'center',
                color: '#606266'
              }"
              @current-change="handleCurrentChange"
            >
              <el-table-column type="index" width="55"> </el-table-column>
              <el-table-column label="匹配名称" prop="match_name">
              </el-table-column>
              <el-table-column label="匹配ID" prop="match_id" sortable>
              </el-table-column>
              <el-table-column label="创建人" prop="creator_name">
              </el-table-column>
              <el-table-column label="创建日期" prop="create_date" sortable>
                <template slot-scope="scope">{{
                  scope.row.create_date | dateYMDHMSFormat
                }}</template>
              </el-table-column>
              <el-table-column label="匹配说明" prop="match_explain">
              </el-table-column>
            </el-table>
            <el-pagination
              @current-change="handlePaginationChange_two"
              :current-page="form_second.page"
              :page-size="form_second.pageSize"
              layout="total, prev, pager, next"
              :total="form_second.pageTotal"
            >
            </el-pagination>
          </div>
        </el-card>
      </el-tab-pane>
      <el-tab-pane label="期权指令" name="third">
        <v-qiquan_order></v-qiquan_order>
      </el-tab-pane>
    </el-tabs>
    <el-dialog
      title="指令自成交-查看"
      :visible.sync="look_dialogVisible_second"
      width="80%"
      :append-to-body="true"
    >
      <el-button
        @click="look_dialogVisible_second = false"
        size="mini"
        class="d2-mb"
        >关闭</el-button
      >
      <el-card shadow="never" class="d2-mb titleline">
        <template slot="header" style="height:66px;">
          <span class="title_x el-button--primary fl"></span>
          <p class="title_l fl">基础信息</p>
        </template>
        <el-table
          :data="tableData_second_look_top"
          style="width: 100%"
          highlight-current-row
          @current-change="handleCurrentChange"
        >
          <el-table-column type="index" width="55"> </el-table-column>
          <el-table-column label="匹配名称" prop="match_name">
          </el-table-column>
          <el-table-column label="匹配ID" prop="match_id"> </el-table-column>
          <el-table-column label="创建人" prop="creator_name">
          </el-table-column>
          <el-table-column label="创建日期" prop="create_date">
            <template slot-scope="scope">{{
              scope.row.create_date | dateYMDHMSFormat
            }}</template>
          </el-table-column>
          <el-table-column label="匹配说明" prop="match_explain">
          </el-table-column>
        </el-table>
      </el-card>
      <el-card shadow="never" class="d2-mb titleline">
        <template slot="header" style="height:66px;">
          <span class="title_x el-button--primary fl"></span>
          <p class="title_l fl">交易信息</p>
        </template>
        <el-table :data="tableData_second_look_bottom" style="width: 100%">
          <el-table-column type="index" width="55"> </el-table-column>
          <el-table-column label="指令ID" prop="command_id"> </el-table-column>
          <el-table-column label="指令名称" prop="command_name">
          </el-table-column>
          <el-table-column label="品名" prop="productName"> </el-table-column>
          <el-table-column label="合约" prop="instrument"> </el-table-column>
          <el-table-column label="方向" prop="direction"> </el-table-column>
          <el-table-column label="开/平" prop="offset_flag"> </el-table-column>
          <el-table-column label="手数" prop="volume"> </el-table-column>
          <el-table-column label="成交价" prop="price"> </el-table-column>
          <el-table-column label="柜台账号" prop="real_account">
          </el-table-column>
          <el-table-column label="子帐号" prop="sub_account"> </el-table-column>
          <el-table-column label="单位" prop="commodity_unit">
          </el-table-column>
          <el-table-column label="备注" prop="remarks"> </el-table-column>
        </el-table>
      </el-card>
    </el-dialog>
  </d2-container>
</template>

<script>
import {
  futures_command_info,
  getFutures_command_info,
  getCommand_self_info,
  getCommand_self_trade,
  getFutures_command_trade,
  command_self_info,
  work_order,
  getUsers,
  currency
} from "@/api/url";
import qiquan_order from "./componnets/add/qiquan_order";
export default {
  data() {
    return {
      form_first: {
        command_trade_type: 1,
        command_name: "",
        command_id: "",
        command_type: "",
        strategy_name: "",
        strategy_id: "",
        department_name: "",
        creator: "",
        status: "",
        page: 1,
        pageSize: 20,
        pageTotal: 0
      },
      tableData_first: [],
      loading_first: false,
      form_second: {
        match_name: "",
        match_id: "",
        create_date: "",
        creator: "",
        page: 1,
        pageSize: 20,
        pageTotal: 0
      },
      tableData_second: [],
      currentRow: null,
      dialogVisible_look: false,
      look_dialogVisible_second: false,
      submit_first_dialogVisible: false, //提交审批弹窗
      tableData_second_look_top: [],
      tableData_second_look_bottom: [],
      tableData_second_update_top: [],
      tableData_second_update_bottom: [],
      currentRow_first: null,
      look_first_data_t: [],
      look_first_data_b: [],
      input: "",
      submit_form: {
        name: ""
      },
      submit_user_data: [],
      tableData: [],
      selectlistRow: [],
      rowNum: 1,
      bz: [],
      activeName: "first",
      // 1.期货指令

      // 新增
      handleFilter_addQqcjVisible: false,
      // 提交审批
      // handleFilter_tjspVisible: false,
      // 修改
      handleFilter_editQqcjVisible: false,
      // 复制
      handleFilter_copyQqcjVisible: false,
      // 调整
      handleFilter_adjustQqcjVisible: false,
      first_statusData: [
        {
          value: 0,
          label: "草拟"
        },
        {
          value: 1,
          label: "审核中"
        },
        {
          value: 4,
          label: "已通过"
        },
        {
          value: 2,
          label: "已驳回"
        },
        {
          value: 3,
          label: "已退审"
        },
        {
          value: 5,
          label: "已下达"
        },
        {
          value: 6,
          label: "已撤销"
        }
      ],
      type_options: [
        {
          value: 1,
          label: "普通指令"
        },
        {
          value: 2,
          label: "调整指令"
        },
        {
          value: 3,
          label: "移仓换月指令"
        }
      ],
      value: "",
      edit_Risk_OrderFormVisible: false,
      egForm: {},
      value: ""

      // 2.资金管理
      // 新增
    };
  },
  components: {
    "v-qiquan_order": qiquan_order
  },
  created() {
    if (sessionStorage.getItem("activeName") == 2) {
      this.activeName = "second";
      this.selectSecond();
    } else if (sessionStorage.getItem("activeName") == 3) {
      this.activeName = "third";
    } else {
      this.selectData();
    }
    currency().then(res => {
      this.bz = res.result.results;
    });
  },
  beforeRouteLeave(to, form, next) {
    if (to.fullPath != "/refresh") {
      sessionStorage.setItem("activeName", "");
    }
    next();
  },
  methods: {
    //比较时间
    checkTime(stime) {
      var dt = new Date();
      var sdate = new Date(Date.parse(stime.replace(/-/g, "/"))); //当前指令结束时间
      let dat = this.formatDate_ss(dt);
      var edate = new Date(Date.parse(dat.replace(/-/g, "/")));
      var smonth = sdate.getMonth() + 1;
      var syear = sdate.getFullYear();
      var sday = sdate.getDate(); //当前指令结束时间

      var emonth = edate.getMonth() + 1;
      var eyear = edate.getFullYear();
      var eday = edate.getDate();
      if (syear > eyear) {
        return true;
      } else {
        if (smonth > emonth) {
          return true;
        } else {
          if (sday >= eday) {
            return true;
          } else {
            return false;
          }
        }
      }
    },
    formatDate_ss(dt) {
      if (!dt) {
        dt = new Date();
      }
      var year = dt.getFullYear();
      var month = dt.getMonth() + 1;
      var date = dt.getDate();
      if (month < 10) {
        // 强制类型转换
        month = "0" + month;
      }
      if (date < 10) {
        // 强制类型转换
        date = "0" + date;
      }
      // 强制类型转换
      return year + "-" + month + "-" + date;
    },
    selectDataone() {
      this.form_first.page = 1;
      this.selectData();
    },
    // 查询
    selectData() {
      getFutures_command_info(this.form_first).then(res => {
        this.tableData_first = res.result.results;
        this.form_first.pageTotal = res.result.count;
      });
    },
    handlePaginationChange(val) {
      this.form_first.page = val;
      this.selectData();
    },
    handlePaginationChange_two(val) {
      this.form_second.page = val;
      this.selectSecond();
    },
    handleClick(tab, event) {
      if (tab.name == "second") {
        this.selectSecond();
      }
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    handleCurrentChange_first(val) {
      this.currentRow_first = val;
    },
    // 期货指令修改
    handleFilter_editCkgl() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
      } else {
        if (
          this.currentRow_first.status == "草拟" ||
          this.currentRow_first.status == "已驳回"
        ) {
          this.$router.push(
            "/update_futures_orders?id=" + this.currentRow_first.command_id
          );
        } else {
          this.$message({
            message: "不可修改",
            type: "warning"
          });
        }
      }
    },
    delete_fn() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
      } else {
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            if (
              this.currentRow_first.status == "草拟" ||
              this.currentRow_first.status == "已驳回"
            ) {
              // console.log(this.currentRow_first)
              var datas = {
                operation: "DEL",
                command_id: this.currentRow_first.command_id
              };
              futures_command_info(datas)
                .then(res => {
                  this.selectData();
                  this.$message({
                    type: "success",
                    message: res.result
                  });
                })
                .catch(err => {
                  this.$message({
                    message: err.msg,
                    type: "warning"
                  });
                });
            } else {
              this.$message({
                message: "只有草拟和已驳回可删除操作",
                type: "warning"
              });
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      }
    },
    look_fn() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
      } else {
        var datas = {
          command_id: this.currentRow_first.command_id
        };
        getFutures_command_info(datas).then(res => {
          this.look_first_data_t = res.result.results;
        });
        getFutures_command_trade(datas).then(res => {
          this.look_first_data_b = res.result.results;
          this.look_first_data_b.forEach(item => {
            this.bz.forEach(bzitem => {
              if (item.currency == bzitem.symbol) {
                item.currency = bzitem.name;
              }
            });
          });
          this.dialogVisible_look = true;
        });
      }
    },
    order_fn_first() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
      } else {
        if (!this.checkTime(this.currentRow_first.end_date)) {
          this.$message({
            message: "指令时间已结束",
            type: "warning"
          });
          return;
        }
        if (this.currentRow_first.status == "已通过") {
          this.$confirm("是否下达指令?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(() => {
              var data = {
                operation: "REL",
                command_id: this.currentRow_first.command_id
              };
              futures_command_info(data)
                .then(res => {
                  this.selectData();
                  this.$message({
                    type: "success",
                    message: res.result
                  });
                })
                .catch(err => {
                  this.$message({
                    message: err.msg,
                    type: "warning"
                  });
                });
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消下达指令"
              });
            });
        } else {
          this.$message({
            message: "只有状态为'已通过',才可以下达指令",
            type: "warning"
          });
        }
      }
    },
    order_fn_first_null() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
      } else {
        if (this.currentRow_first.status != "已下达") {
          this.$message({
            message: "只有状态为'已下达',才可以撤销指令",
            type: "warning"
          });
          return;
        }
        this.$confirm("是否撤销指令?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            var data = {
              operation: "CAN",
              command_id: this.currentRow_first.command_id
            };
            futures_command_info(data)
              .then(res => {
                this.selectData();
                this.$message({
                  type: "success",
                  message: res.result
                });
              })
              .catch(err => {
                this.$message.error(err.msg);
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消撤销指令"
            });
          });
      }
    },
    //提交审批
    submit_first_dialogVisible_fn() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
        return;
      }
      this.loading_first = true;
      let objToStr = JSON.stringify(this.currentRow_first);
      var data = {
        operation: "ADD",
        task: "ORDER",
        desc: objToStr,
        business_id: this.currentRow_first.command_id
      };
      work_order(data)
        .then(res => {
          this.loading_first = false;
          this.selectData();
          this.$message({
            type: "success",
            message: res.result
          });
        })
        .catch(err => {
          this.loading_first = false;
          this.$message.error(err.msg);
        });
    },
    tiaozhuan() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
      } else {
        if (this.currentRow_first.workOrderID == 0) {
          this.$message({
            message: "未进入审批历史",
            type: "warning"
          });
          return;
        }
        this.$router.push(
          "/examine_historyss?id=" + this.currentRow_first.workOrderID
        );
      }
    },
    // 提交审批
    //  设计图上要选择审批人 但是张龙说暂时不用选
    // handleFilter_qhzlTjsp() {
    //   console.log(1)
    //   if (this.currentRow_first === null) {
    //     this.$message({
    //       message: "请先选择期货指令",
    //       type: "warning"
    //     });
    //   } else {
    //     this.submit_first_dialogVisible = true;
    //     getUsers().then(res => {
    //       this.submit_user_data = res.result;
    //     });
    //   }
    // },
    handleFilter_qhzlTjsp_tui() {
      if (this.currentRow_first === null) {
        this.$message({
          message: "请先选择期货指令",
          type: "warning"
        });
      } else {
        if (this.currentRow_first.status != "审核中") {
          this.$message({
            message: "只有状态为审核中才能退审",
            type: "warning"
          });
          return;
        }
        var data = {
          operation: "MOD",
          id: this.currentRow_first.workOrderID,
          status: 3,
          opinion: ""
        };
        work_order(data)
          .then(res => {
            this.selectData();
            this.$message({
              type: "success",
              message: res.result
            });
          })
          .catch(err => {
            this.$message.error(err.msg);
          });
      }
    },
    //第二块
    // 查看弹窗
    look_second_fn() {
      if (this.currentRow === null) {
        this.$message({
          message: "请先选择指令自成交",
          type: "warning"
        });
      } else {
        this.look_dialogVisible_second = true;
        this.tableData_second_look_top = [];
        this.tableData_second_look_top.push(this.currentRow);
        var datas = {
          match_id: this.currentRow.match_id
        };
        getCommand_self_trade(datas).then(res => {
          this.tableData_second_look_bottom = res.result.results;
        });
      }
    },
    update_second_fn() {
      if (this.currentRow === null) {
        this.$message({
          message: "请先选择指令自成交",
          type: "warning"
        });
      } else {
        this.$router.push(
          "/update_order_self-clinching?id=" + this.currentRow.match_id
        );
      }
    },
    update_second_save() {},
    handleFilter_delCkgl() {
      if (this.currentRow === null) {
        this.$message({
          message: "请先选择指令自成交",
          type: "warning"
        });
        return;
      }
      this.$confirm("是否删除匹配?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          var data = {
            operation: "DEL",
            match_id: this.currentRow.match_id
          };
          command_self_info(data)
            .then(res => {
              this.$message({
                type: "success",
                message: res.result
              });
              this.selectSecond();
            })
            .catch(err => {
              this.$message({
                message: err.msg,
                type: "warning"
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    handleFilter_copyCkgl() {},
    load(tree, treeNode, resolve) {
      setTimeout(() => {
        resolve([
          {
            id: 31,
            date: "2016-05-01",
            name: "王小虎",
            address: "上海市普陀区金沙江路 1519 弄"
          },
          {
            id: 32,
            date: "2016-05-01",
            name: "王小虎",
            address: "上海市普陀区金沙江路 1519 弄"
          }
        ]);
      }, 1000);
    },
    // 单选
    handleCurrentChange(datas) {
      this.currentRow = datas;
    },
    // 多选
    handleSelectionChange(selection) {
      console.log(selection);
    },
    // 清空当前页缓存并刷新此页面
    handleCleanCacheAndRefreshCurrent(nums) {
      sessionStorage.setItem("activeName", nums);
      this.$nextTick();
      this.$router.replace("/refresh");
    },
    // 1.期货指令
    // 新增和赋值 1为新增其他为复制
    handleFilter_addqhzl(index) {
      this.$store.commit("SET_SELECTIONSTRATEGY_VUE", "");
      if (index == 1) {
        this.$router.push("/add_futures_orders?status=" + "null");
      } else {
        if (this.currentRow_first === null) {
          this.$message({
            message: "请先选择指令自成交",
            type: "warning"
          });
        } else {
          this.$router.push(
            "/add_futures_orders?status=" + this.currentRow_first.command_id
          );
        }
      }
    },
    //  提交审批保存
    tjspChange() {},
    // 下达指令
    handleFilter_addxdzl(val) {
      this.$confirm("是否确定下达指令？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          alert(2);
          this.xdzlChange();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消下达指令"
          });
        });
    },
    //  下达指令保存
    xdzlChange() {},
    // 撤销指令
    handleFilter_addcxzl(val) {
      this.$confirm("是否确定撤销指令？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.cxzlChange();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消撤销指令"
          });
        });
    },
    //  撤销指令保存
    cxzlChange() {},
    // 2.指令自成交
    handleFilter_addzlzcj() {
      this.$router.push({ path: "/add_order_self-clinching" });
    },

    // 获取表格选中时的数据
    selectRow(val) {
      this.selectlistRow = val;
    },
    // 增加行
    addRow() {
      var list = {
        rowNum: this.rowNum,
        post_id: [],
        require_des: "",
        text: ""
      };
      this.tableData.unshift(list);
      this.rowNum += 1;
    },
    // 删除方法
    // 删除选中行
    delData() {
      for (let i = 0; i < this.selectlistRow.length; i++) {
        let val = this.selectlistRow;
        val.forEach((val, index) => {
          this.tableData.forEach((v, i) => {
            if (val.rowNum === v.rowNum) {
              // i 为选中的索引
              this.tableData.splice(i, 1);
            }
          });
        });
      }
      // 删除完数据之后清除勾选框
      this.$refs.table.clearSelection();
    },
    // 修改
    handleFilter_editQqcj() {
      this.handleFilter_editQqcjVisible = true;
    },
    //  复制
    handleFilter_copyQqcj() {
      this.handleFilter_copyQqcjVisible = true;
    },
    // 调整
    handleFilter_adjustQqcj() {
      this.handleFilter_adjustQqcjVisible = true;
    },

    selectSecond() {
      // this.form_second.page=1
      getCommand_self_info(this.form_second).then(res => {
        // console.log(res)
        this.tableData_second = res.result.results;
        this.form_second.pageTotal = res.result.count;
      });
    }
  }
};
</script>
